//
//  PKHomeSectionCell.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/28.
//

import UIKit
import RxSwift
import RxCocoa
import RxDataSources
import SnapKit
class PKHomeSectionCell: UICollectionViewCell {
    
    var collectionView : UICollectionView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        let flowLayout = UICollectionViewFlowLayout()
                flowLayout.itemSize = CGSize(width: 100, height: 100)
        flowLayout.minimumInteritemSpacing = 10
        flowLayout.minimumLineSpacing = 10
        flowLayout.scrollDirection = .horizontal
        flowLayout.sectionInset = .init(top: 10, left: 10, bottom: 10, right: 10)
                //创建集合视图
        self.collectionView = UICollectionView(frame: .zero,
                                                       collectionViewLayout: flowLayout)
         self.collectionView.backgroundColor = UIColor.white
        contentView.addSubview(collectionView)
        collectionView.register(UINib.init(nibName: "PKHomeCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "PKHomeCollectionViewCell")
 
        let dataSource = RxCollectionViewSectionedReloadDataSource<SectionModel<String, String>>(
            configureCell: { _, collectionView, indexPath, item in
                let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PKHomeCollectionViewCell", for: indexPath) as! PKHomeCollectionViewCell
//                cell.label.text = "\(indexPath.row)：\(item)"
                cell.imageView.image = UIImage(named: "cards_1")
                return cell
            })

        Observable.just([SectionModel(model: "Languages", items: ["Swift", "PHP", "Ruby", "Java", "C++"])])
            .bind(to: collectionView.rx.items(dataSource: dataSource))
            .disposed(by: rx.disposeBag)
        
        self.collectionView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
